package cc.vv.btpartyjob.partymanager.adapter

import android.annotation.SuppressLint
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import cc.vv.baselibrary.adapter.SimpleCommonAdapter
import cc.vv.baselibrary.adapter.holder.ExtendViewHolder
import cc.vv.btparty.view.RatingStarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.EvaluationStarBean
import cc.vv.lkimagecomponent2.LKImage

/**
 * 评星晋级adapter
 * Created by Chen.qi on 2018/10/24.
 */
class StarAdapter(layoutResId: Int) : SimpleCommonAdapter<EvaluationStarBean>(layoutResId) {
    @SuppressLint("SetTextI18n")
    override fun convert(helper: ExtendViewHolder, item: EvaluationStarBean, position: Int) {
        //第一二三名
        val starPic = helper.getView<ImageView>(R.id.tv_ieStar_pic)
        //位置
        val starPostion = helper.getView<TextView>(R.id.tv_ieStar_position)
        //标题
        val starTitle = helper.getView<TextView>(R.id.tv_itStar_title)
        //星星
        val starNum = helper.getView<RatingStarView>(R.id.rsv_itStar_num)
        //得分
        val score = helper.getView<TextView>(R.id.tv_ieStar_score)

        when (position) {
            0 -> {
                LKImage.load().loadRes(R.mipmap.icon_ptman_star_one).into(starPic)
                starPic?.visibility = View.VISIBLE
                starPostion?.visibility = View.GONE
            }
            1 -> {
                LKImage.load().loadRes(R.mipmap.icon_ptman_star_two).into(starPic)
                starPic?.visibility = View.VISIBLE
                starPostion?.visibility = View.GONE
            }
            2 -> {
                LKImage.load().loadRes(R.mipmap.icon_ptman_star_three).into(starPic)
                starPic?.visibility = View.VISIBLE
                starPostion?.visibility = View.GONE
            }
            else -> {
                starPic?.visibility = View.GONE
                starPostion?.visibility = View.VISIBLE
                starPostion?.text = "${position + 1}"
            }
        }
        starTitle?.text = item.companyName

        if (null != item.score) {
            if (item.score!! >= 96f) {
                starNum?.initData(5)
            } else if (91 <= item.score!! && item.score!! < 96) {
                starNum?.initData(4)
            } else if (85 <= item.score!! && item.score!! < 91) {
                starNum?.initData(3)
            } else if (75 <= item.score!! && item.score!! < 85) {
                starNum?.initData(2)
            } else if (60 <= item.score!! && item.score!! < 75) {
                starNum?.initData(1)
            } else {
                starNum?.initData(0)
            }
        } else {
            starNum?.initData(0)
        }
        score?.text = "${item.score}"
    }
}